#!/bin/sh

# count.sh
# 
#
# Created by ［CGM］sgxiao on 08-12-15.
# Copyright 2008 CGM Inc. All rights reserved.

startYear=1994
endYear=2008
COUNT=count
DATA=data
RESULT=result.doc
filename=$1

#if [ -z ${filename} ]
#then
#	echo "please input the filename:"
#	read filename
#fi

#mkdir ${COUNT}
touch ${RESULT}

while [ ${startYear} -le ${endYear} ]
do
	echo ${startYear}
	awk -f count.awk ${startYear}.${DATA} | uniq - > ${startYear}.${COUNT}
	
	#cat ${startYear}.${DATA} | uniq - > ${startYear}.COUNT
	
	# generating result.doc
	echo "`wc -l ${startYear}.${COUNT} | cut -d . -f 1`"  >> ${RESULT}
	startYear=$((startYear + 1))		

done

#mv *.${COUNT} ./${COUNT}/
#mv ${RESULT} ./${COUNT}/
mv *.data ../